package com.drodds.game;

public class Range<T> implements Comparable<Object> {
	final int bottom;
	final int top;
	final WeightedItem<T> weightedItem;
	
	public Range(int bottom, int top, WeightedItem<T> wi) {
		this.bottom = bottom;
		this.top = top;
		this.weightedItem = wi;
	}
	
	public WeightedItem<T> getWeightedItem() {
		return weightedItem;
	}
	
	@Override
	public int compareTo(Object arg0) {
		if (arg0 instanceof Range<?>) {
			Range<?> other = (Range<?>) arg0;
			if(this.bottom > other.top) 
				return 1;
			if(this.top < other.bottom)
				return -1;
			return 0;
		}
		else if (arg0 instanceof Integer) {
			Integer other = (Integer)arg0;
			if (this.bottom > other.intValue())
				return 1;
			if (this.top < other.intValue())
				return -1;
			return 0;
		}
		throw new IllegalArgumentException(String.format("Cannot compare Range to %s.", arg0.getClass().getName()));
	}
	
	@Override
	public String toString() {
		StringBuilder builder = new StringBuilder();
		builder.append("{\"_class\": Range {\"bottom\":\"").append(bottom).append("\", \"top\":\"").append(top).append("\", \"weightedItem\":\"").append(weightedItem).append("}");
		return builder.toString();
	}
	
	
}
